// <editor-fold defaultstate="collapsed" desc="GNU GPLv3 Header">
/*
 * File:   LittleEndianBinaryFileOps.java
 *
 * Copyright (C) 2013 Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * Copyright (C) 2013 David Megias Jimenez <dmegias@uoc.edu>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
// </editor-fold>
package readwave;

// <editor-fold defaultstate="collapsed" desc="imports">
import java.io.DataInputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
// </editor-fold>

/**
 *
 * @author Robert Antoni Buj Gelonch <rbuj@uoc.edu>
 * @version 1.0
 * @since 2013-08-04
 */
class LittleEndianBinaryFileOps {

    LittleEndianBinaryFileOps() {
    }

    /**
     *
     * @param dis
     * @return a char in Big Endian
     * @see char
     *
     * @since 2013-08-04
     */
    public char readAsciiCharLE(DataInputStream dis) throws IOException {
        return (char) readByteLE(dis);
    }

    /**
     *
     * @param dis
     * @return a byte in Big Endian
     * @see byte
     *
     * @since 2013-08-04
     */
    public byte readByteLE(DataInputStream dis) throws IOException {
        return dis.readByte();
    }

    /**
     *
     * @param dis
     * @return a Short in Big Endian
     * @see int
     *
     * @since 2013-08-04
     */
    public short readShortLE(DataInputStream dis) throws IOException {
        byte[] buffer = new byte[2];
        dis.read(buffer);
        return ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).getShort();
    }

    /**
     *
     * @param dis
     * @return a Long in Big Endian
     * @see int
     *
     * @since 2013-08-04
     */
    public int readLongLE(DataInputStream dis) throws IOException {
        byte[] buffer = new byte[4];
        dis.read(buffer);
        return ByteBuffer.wrap(buffer).order(ByteOrder.LITTLE_ENDIAN).getInt();
    }
}
